package com.itheima.appserver.controller;

import com.itheima.appserver.service.MyCenterService;
import com.itheima.commons.vo.UserInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("users")
@RestController
@Slf4j
public class MyCenterController {

    @Autowired
    private MyCenterService myCenterService;

    /**
     * 根据用户id查询用户信息
     *
     * @param userId 用户id，如果为空，表示查询当前登录人的信息
     * @return
     */
    @GetMapping
    public ResponseEntity queryUserInfoByUserId(@RequestParam(value = "userID", required = false) Long userId) {
        UserInfoVo userInfoVo = myCenterService.queryUserInfoByUserId(userId);
        return ResponseEntity.ok(userInfoVo);
    }
}